/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package chating;
import database.Database;
import chating.User;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Andi
 */
public class Admin {
    public void changeMaxRoomsUser(User user, int maxRooms){
        user.setMaxRooms(maxRooms);
        Database db = new Database();
        try {
            db.setUserMaxRooms(user.getUserName(), maxRooms);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void banUser(User user){
        user.setBan(true);
        Database db = new Database();
        try {
            db.banUser(user.getUserName());
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void unBanUser(User user){
        user.setBan(false);
        Database db = new Database();
        try {
            db.unBanUser(user.getUserName());
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void createCategory(String categoryName){
        Database db = new Database();
        try {
            db.addKategori(categoryName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }

    public void createSubCategory(String subCategoryName, String categoryName){
        Database db = new Database();
        try {
            db.addSubKategori(subCategoryName,categoryName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void editCategory(String categoryName, String newName){
        Database db = new Database();
        try {
            db.editKategori(categoryName, newName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void deleteCategory(String categoryName){
        Database db = new Database();
        try {
            db.deleteKategori(categoryName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setUserAsModerator(User u, String categoryName){
        Database db = new Database();
        u.setRole("moderator");
        try {
            db.addModerator(u.getUserName(), categoryName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void editUserAsModerator(User u, String categoryName){
        Database db = new Database();
        try {
            db.editModerator(u.getUserName(), categoryName);
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void deleteUserAsModerator(User u){
        Database db = new Database();
        u.setRole("user");
        try {
            db.deleteModerator(u.getUserName());
        } catch (SQLException ex) {
            Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }



}
